From: Adam Moore <adamoore@yahoo-inc.com>
To: Kent Brewster <brewster@yahoo-inc.com>
Cc: 
Bcc: 
Subject: Re: [devel-frontend] Weird Internet Explorer Issue with YUI/YLC JS Libs
Reply-To: 
In-Reply-To: <454F651D.5060404@yahoo-inc.com>

On Mon, Nov 06, 2006 at 08:38:53AM -0800, Kent Brewster wrote:
> 
> Thanks for the pointer; I will start using it as soon as one minor thing 
> is cleared up.  Can you please say more about the effective difference 
> (if any) between this:
> 
> if (typeof YAHOO == "undefined") {
>     YAHOO = {};
> }

This one will trigger a warning in Gecko "strict mode" for an undefined
global.

> 
> and this:
> 
> if (typeof YAHOO == "undefined") {
>     var YAHOO = {};
> }

This one will trigger a jslint warning for referencing a variable before
it is declared.

The only functional difference that I am aware of is what happens if you 
do this inside of another function:

(function() {
    // undeclared variables are globally scoped, so this is accessible 
    // everywhere, and also would overwrite an existing global YAHOO.
    YAHOO = {};
})();

(function() {
    // local scope, can only be accessed inside of the anonymous 
    // function.  If a global YAHOO exists, it will survive.  References
    // to YAHOO here will refer to the locally scoped YAHOO, while
    // references outside will refer to the original global.
    var YAHOO = {}; 
})();



-Adam

